package com.cskaoyan.user.controller.feign;

import com.cskaoyan.user.UserVerifyDTO;
import com.cskaoyan.user.converter.UserToOrderConverterMapper;
import com.cskaoyan.user.dal.entitys.UserVerify;
import com.cskaoyan.user.dal.persistence.UserVerifyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cskaoyan.user.MemberDTO;
import com.cskaoyan.user.UserVerifyDTO;
import com.cskaoyan.user.converter.UserToOrderConverterMapper;
import com.cskaoyan.user.dal.entitys.Member;
import com.cskaoyan.user.dal.entitys.UserVerify;
import com.cskaoyan.user.dal.persistence.MemberMapper;
import com.cskaoyan.user.dal.persistence.UserVerifyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;
import java.util.List;


/**
 * @author silic xia
 * @since 2022/12/03 18:13
 */
@RestController
public class OrderFeignController {

    @Autowired
    MemberMapper memberMapper;
    @Autowired

    UserVerifyMapper userVerifyMapper;
    @Autowired
    UserToOrderConverterMapper userToOrderConverterMapper;


    @GetMapping("/feign/order")
    public UserVerifyDTO selectUserVerifyByPrimaryKey(Long userId){
        UserVerify userVerify = userVerifyMapper.selectByPrimaryKey(userId);
        UserVerifyDTO userVerifyDTO = userToOrderConverterMapper.userVerifyToUserVerifyDTO(userVerify);
        return userVerifyDTO;
    }

    @GetMapping("/feign/order/checkMember")
    public MemberDTO selectMemberByPrimaryKey(Long userId){
        Member member = memberMapper.selectByPrimaryKey(userId);
        MemberDTO memberDTO = userToOrderConverterMapper.memberToMemberDTO(member);
        return memberDTO;
    }

    @GetMapping("/feign/order/checkUserVerify")
    public UserVerifyDTO selectUserVerifyByPrimaryKey(String username){
        Example example = new Example(UserVerify.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("username",username);
        List<UserVerify> userVerifies = userVerifyMapper.selectByExample(example);
        UserVerifyDTO userVerifyDTO = userToOrderConverterMapper.userVerifyToUserVerifyDTO(userVerifies.get(0));
        return userVerifyDTO;
    }

}

